/**
 * 配音管理相关API类型定义
 */

import type { PageParams } from './common'

// 用户配音响应
export interface UserRecordingRespVO {
  id: number
  bookId: number
  bookTitle: string
  coverUrl: string
  audioUrl: string
  score?: number
  recordTime: string
  isShareable: boolean
  duration: string // 格式化为 MM:SS
}

// 用户配音创建请求
export interface UserRecordingCreateReqVO {
  bookId: number
  pageNumber?: number
  audioUrl: string
  duration: number
  title?: string
  description?: string
  isPublic?: boolean
  tags?: string[]
}

// 用户配音详情响应
export interface UserRecordingDetailRespVO extends UserRecordingRespVO {
  userNickname: string
  userAvatar?: string
  isLiked: boolean
  canEdit: boolean
  canDelete: boolean
  relatedRecordings?: UserRecordingRespVO[]
  comments?: Array<{
    id: number
    userId: number
    userNickname: string
    userAvatar?: string
    content: string
    createTime: string
  }>
}

// 用户配音列表参数
export interface UserRecordingListParams extends PageParams {
  bookId?: number
  status?: 'draft' | 'published' | 'deleted'
  isPublic?: boolean
  keyword?: string
  sortBy?: 'createTime' | 'playCount' | 'likeCount' | 'score'
  sortOrder?: 'asc' | 'desc'
  tags?: string[]
}

// 配音分享信息
export interface RecordingShareInfo {
  recordingId: number
  shareText: string
  shareImage: string
  shareUrl: string
  qrCodeUrl: string
}

// 用户配音聚合响应
export interface UserRecordingAggregateRespVO {
  bookId: number
  bookTitle: string
  coverUrl: string
  recordingCount: number
  totalDuration: number
  formattedTotalDuration: string
  averageScore?: number
  latestRecordTime: string
  allShareable: boolean
  totalPages: number
  recordedPages: number
  completionPercentage: number
}

// 用户配音详情页响应
export interface UserRecordingDetailPageRespVO {
  bookId: number
  bookTitle: string
  coverUrl: string
  totalPages: number
  recordedPages: number
  completionPercentage: number
  allShareable: boolean
  pageRecordings: PageRecordingVO[]
}

// 页面配音信息
export interface PageRecordingVO {
  pageId: number
  pageNumber: number
  imageUrl: string
  textContent: string
  hasRecording: boolean
  recordingId?: number
  audioUrl?: string
  duration?: number
  formattedDuration?: string
  score?: number
  isShareable: boolean
  recordTime?: string
  recordingQuality?: string
}

// 配音公开设置请求
export interface UserRecordingPublicSettingReqVO {
  bookId: number
  isPublic: boolean
}

// 配音分享响应
export interface UserRecordingShareRespVO {
  bookId: number
  shareText: string
  shareImage: string
  shareUrl: string
  qrCodeUrl: string
  shareTitle: string
  shareDescription: string
}

// 配音统计响应
export interface RecordingStatsRespVO {
  totalRecordings: number
  totalDuration: number
  totalPlayCount: number
  totalLikeCount: number
  averageScore: number
  publishedCount: number
  draftCount: number
  // 月度统计
  monthlyStats: Array<{
    month: string
    recordingCount: number
    totalDuration: number
    averageScore: number
  }>
  // 热门配音
  popularRecordings: UserRecordingRespVO[]
  // 最近配音
  recentRecordings: UserRecordingRespVO[]
}

// 配音上传响应
export interface RecordingUploadRespVO {
  audioUrl: string
  duration: number
  fileSize: number
  format: string
  quality: 'low' | 'medium' | 'high'
}

// 配音评分请求
export interface RecordingScoreReqVO {
  recordingId: number
  score: number // 1-100
  feedback?: string
}

// 配音评分响应
export interface RecordingScoreRespVO {
  recordingId: number
  score: number
  averageScore: number
  scoreCount: number
  feedback?: string
}

// 配音模板
export interface RecordingTemplate {
  id: number
  name: string
  description: string
  bookId: number
  bookTitle: string
  pageNumber: number
  sampleAudioUrl: string
  difficulty: 'easy' | 'medium' | 'hard'
  tags: string[]
  isRecommended: boolean
}

// 配音挑战
export interface RecordingChallenge {
  id: number
  title: string
  description: string
  bookId: number
  bookTitle: string
  bookCover: string
  startTime: string
  endTime: string
  participantCount: number
  maxParticipants?: number
  prizes?: string[]
  rules: string[]
  status: 'upcoming' | 'active' | 'ended'
}

// 配音排行榜
export interface RecordingRankingRespVO {
  userId: number
  userNickname: string
  userAvatar?: string
  totalRecordings: number
  totalPlayCount: number
  totalLikeCount: number
  averageScore: number
  rank: number
  isCurrentUser?: boolean
}

// 配音成就
export interface RecordingAchievement {
  id: number
  name: string
  description: string
  icon: string
  condition: string
  isUnlocked: boolean
  unlockDate?: string
  progress?: number
  maxProgress?: number
  reward?: string
}

// 配音设置
export interface RecordingSettings {
  autoSave: boolean
  defaultPublic: boolean
  enableNotifications: boolean
  qualityPreference: 'low' | 'medium' | 'high'
  maxDuration: number // 秒
  allowComments: boolean
  allowDownload: boolean
}

// 配音导出参数
export interface RecordingExportParams {
  recordingIds: number[]
  format: 'mp3' | 'wav' | 'zip'
  includeMetadata?: boolean
}

// 配音分析数据
export interface RecordingAnalysisRespVO {
  recordingId: number
  duration: number
  averageVolume: number
  peakVolume: number
  silenceRatio: number
  speechRate: number // 语速，每分钟字数
  pronunciationScore?: number
  fluencyScore?: number
  intonationScore?: number
  suggestions: string[]
}

// 配音比较结果
export interface RecordingComparisonRespVO {
  userRecordingId: number
  officialAudioUrl: string
  similarityScore: number
  timingAccuracy: number
  pronunciationAccuracy: number
  suggestions: string[]
  improvements: Array<{
    timeStart: number
    timeEnd: number
    issue: string
    suggestion: string
  }>
}
